.lcomm pgaj,32
.lcomm gajieni,32*32
.lcomm gajcod,32*4  
.lcomm teklim,4
.text
.globl lmeklet
lmeklet:
pushfl
pushal
MOV  44(%esp),%ebx
mov $pagriez0,%eax
mov  %eax,gajcod 
movl $0,teklim 
mov  $pagriez0,%edx
mov  $gajieni+23,%edi
std
mov $0,%eax
ievvertc:
mov  $24,%ecx
ievvert:
mov %ebx,%esi
movb  -1(%edx,%ecx,1),%al
add %eax,%esi
movsb 
loop ievvert
mov $6,%ecx
mov %ebx,%esi
add $20,%esi
mov $pgaj+20,%edi
rep movsl  
mov $gajieni,%ebx
jmp parbpoz
limmain:
mov $gajcod,%edx
mov teklim,%ecx
inc %ecx
mov $pagriez11,%eax
limcik:
cmp -4(%edx,%ecx,4),%eax
jnz atrlim
loop limcik
incl teklim
push $0
mov teklim,%edi
shl $2,%edi
add $gajcod,%edi
mov teklim,%ecx
inc %ecx
jmp atmgaj
atrlim:
dec %ecx
add  $24,(%edx,%ecx,4)
cmp teklim,%ecx
jz parbpl
push %ecx
mov teklim,%edi
shl $2,%edi
add $gajcod,%edi
sub teklim,%ecx
neg %ecx
atmgaj:
mov $pagriez0,%eax
rep stosl 
pop  %ecx
parbpl:
call atjgaj
mov teklim,%ebx
shl $5,%ebx
add $gajieni,%ebx
parbpoz:
mov $0,%eax
mov $pagriez0,%edx
jmp sakp
gajmain:
add $24,%edx
cmp $pagriez11+1,%edx
jnc limmain
sakp:
mov $24,%ecx
lopcik:
loop parbcikls
jmp izeja
parbcikls:
movb (%edx,%ecx,1),%al
cmpb (%ebx,%eax,1),%cl
jz lopcik
jmp gajmain
izeja:
mov $24,%eax
MOV  40(%esp),%ebx
mov teklim,%ecx
add $2,%ecx
nakrez:
sub $pagriez0,%edx
shr $3,%edx
movb %dl,-1(%ebx,%ecx,1)
mov $gajcod,%edx
mov -8(%edx,%ecx,4),%edx
loop nakrez
popal
mov teklim,%eax
inc %eax
popfl
ret 
ievvc:
push %ecx
mov  $24,%ecx
ievvertv:
mov %ebx,%esi
movb  -1(%edx,%ecx,1),%al
add %eax,%esi
movsb 
loop ievvertv
pop %ecx
ret
atjgaj:
mov $0,%eax
shl $2,%ecx
mov %ecx,%edx
add $gajcod,%edx
shl $3,%ecx
mov %ecx,%ebx
add $pgaj,%ebx
mov teklim,%ecx
shl $5,%ecx
add $gajieni-1,%ecx
atkiev:
mov %ebx,%edi
add $55,%edi
push %edx
mov (%edx),%edx
call ievvc
pop %edx
add $4,%edx
add $32,%ebx
cmp %edi,%ecx
jnz atkiev
ret
.data
pagriez0:
.byte 0x03,0x00,0x01,0x02,0x04,0x05,0x06,0x07,0x11,0x10,0x0A,0x0B,0x15,0x14,0x0E,0x0F,0x0C,0x0D,0x12,0x13,0x08,0x09,0x16,0x17
pagriez1:
.byte 0x00,0x01,0x02,0x03,0x05,0x06,0x07,0x04,0x08,0x09,0x16,0x17,0x0C,0x0D,0x12,0x13,0x10,0x11,0x0B,0x0A,0x14,0x15,0x0F,0x0E
pagriez2:
.byte 0x00,0x15,0x16,0x03,0x04,0x11,0x12,0x07,0x0B,0x08,0x09,0x0A,0x0C,0x0D,0x0E,0x0F,0x10,0x02,0x01,0x13,0x14,0x06,0x05,0x17
pagriez3:
.byte 0x13,0x01,0x02,0x10,0x17,0x05,0x06,0x14,0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x0C,0x04,0x11,0x12,0x07,0x00,0x15,0x16,0x03
pagriez4:
.byte 0x09,0x0A,0x02,0x03,0x0D,0x0E,0x06,0x07,0x08,0x05,0x04,0x0B,0x0C,0x01,0x00,0x0F,0x11,0x12,0x13,0x10,0x14,0x15,0x16,0x17
pagriez5:
.byte 0x00,0x01,0x0C,0x0F,0x04,0x05,0x08,0x0B,0x03,0x09,0x0A,0x02,0x07,0x0D,0x0E,0x06,0x10,0x11,0x12,0x13,0x17,0x14,0x15,0x16
pagriez6:
.byte 0x01,0x02,0x03,0x00,0x04,0x05,0x06,0x07,0x14,0x15,0x0A,0x0B,0x10,0x11,0x0E,0x0F,0x09,0x08,0x12,0x13,0x0D,0x0C,0x16,0x17
pagriez7:
.byte 0x00,0x01,0x02,0x03,0x07,0x04,0x05,0x06,0x08,0x09,0x13,0x12,0x0C,0x0D,0x17,0x16,0x10,0x11,0x0E,0x0F,0x14,0x15,0x0A,0x0B
pagriez8:
.byte 0x00,0x12,0x11,0x03,0x04,0x16,0x15,0x07,0x09,0x0A,0x0B,0x08,0x0C,0x0D,0x0E,0x0F,0x10,0x05,0x06,0x13,0x14,0x01,0x02,0x17
pagriez9:
.byte 0x14,0x01,0x02,0x17,0x10,0x05,0x06,0x13,0x08,0x09,0x0A,0x0B,0x0F,0x0C,0x0D,0x0E,0x03,0x11,0x12,0x00,0x07,0x15,0x16,0x04
pagriez10:
.byte 0x0E,0x0D,0x02,0x03,0x0A,0x09,0x06,0x07,0x08,0x00,0x01,0x0B,0x0C,0x04,0x05,0x0F,0x13,0x10,0x11,0x12,0x14,0x15,0x16,0x17
pagriez11:
.byte 0x00,0x01,0x0B,0x08,0x04,0x05,0x0F,0x0C,0x06,0x09,0x0A,0x07,0x02,0x0D,0x0E,0x03,0x10,0x11,0x12,0x13,0x15,0x16,0x17,0x14
